<%@ language="vbscript"%>
<%
	Session("bChucnang")=3
	Session("FormName")="F12"
%>
<!--#include file="..\..\CheckSession.inc"-->
<!--#include file=..\..\getFormName.inc-->
<%  
	Dim bLink 
	Set ClsFun =server.CreateObject("Vinalines.ClsFunction")	
	bComm=Request("bComm")
	bMa=Request("bMa")
	bMacu=Request("bMacu")
	bHoten=Request("bHoten")
	bManhom=Session("bManhom")
	bNgaysinh=Request("bNgaysinh")
	Loaitim=request("Combovalue")
	bsearch=request("Txtsearch")
	Dim bTempComm
	Dim TotalN	
	Set Rec=server.CreateObject("ADODB.Recordset") 
	rec.CursorType = 3
	rec.CacheSize=5
	'*****Remove can bo vao nhom*********
	if request("bComm")="remove" then		
		Max=Request("TotalMax")		
		if max="" then max=0
		On error resume next
		Conn.BeginTrans
		
		for i=1 to Max
			ten="cb"+cstr(i)
			bcheck=request(ten)
			if bcheck<>"" then
				ten="Ma"+cstr(i)
				bMa=request(ten)
				bLoai=Session("bManhom")
				sSQL="Select * from diachiluutru where diachi like '"& bloai &"' and nguoiphutrach like '"& bma &"'"
				Set RecKT=server.CreateObject("ADODB.Recordset")
				RecKT.CursorType=3
				RecKT.CacheSize=5
				RecKT.Open sSQL,Conn
				if RecKT.RecordCount<=0 then
					ssql="Delete from canbo_nhom where macanbo like '" & bma & "' and manhom like '" & bloai & "'"
					Conn.Execute ssql
				end if
				RecKT.Close
				Set RecKT=nothing
			end if
			if Err.number<>0 then
				Exit For
			end if
		next
		if Err.number=0 then
			Conn.CommitTrans
		else
			Conn.RollbackTrans
		end if
	end if
	select case trim(Loaitim)
		case "ma"
			ssql="SELECT Canbo.Macanbo, Canbo.Hovaten, Canbo.Ngaysinh FROM Nhom INNER JOIN (Canbo INNER JOIN Canbo_Nhom ON Canbo.Macanbo = Canbo_Nhom.Macanbo) ON Nhom.Manhom = Canbo_Nhom.Manhom where Nhom.Manhom like '"& bmanhom &"' and Canbo.Macanbo like '%"& ClsFun.ModiString(bSearch)& "%' order by username"
			'ssql="Select * from canbo_nhom where Macanbo like '%"& ClsFun.ModiString(bsearch) & "%' order by Macanbo"
		case "ten"	
			ssql="SELECT Canbo.Macanbo, Canbo.Hovaten, Canbo.Ngaysinh FROM Nhom INNER JOIN (Canbo INNER JOIN Canbo_Nhom ON Canbo.Macanbo = Canbo_Nhom.Macanbo) ON Nhom.Manhom = Canbo_Nhom.Manhom where Nhom.Manhom like '"& bmanhom &"' and Canbo.Hovaten like '%"& ClsFun.ModiString(bSearch)& "%' order by username"
			'ssql="Select * from canbo_nhom where hovaten like '%"& ClsFun.ModiString(bsearch) & "%' order by Macanbo"
		case else
			Loaitim=""
			bsearch=""
			ssql="SELECT Canbo.Macanbo, Canbo.Hovaten, Canbo.Ngaysinh FROM Nhom INNER JOIN (Canbo INNER JOIN Canbo_Nhom ON Canbo.Macanbo = Canbo_Nhom.Macanbo) ON Nhom.Manhom = Canbo_Nhom.Manhom where Nhom.Manhom like '"& bmanhom &"' order by username"
			'ssql="Select * from canbo order by Macanbo"
	end select
	rec.Open ssql,Conn
	'**********************************
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Gi</title>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function CmdSearch_onclick() {
	loai=frm.ComboValue.value;
	value=frm.TxtSearch.value;
	blink="frmdaphannhom.asp?Loaitim="+loai+"&bsearch="+value+"&bComm=search";
	window.frm.action=blink;
	window.frm.submit();
}
function checkallCB_onclick() {
	<%for i=1 to Rec.recordcount%>
		if (frm.checkallCB.checked ){
			frm.cb<%=i%>.checked=true;
		}
		else{
			frm.cb<%=i%>.checked=false;
		}
	<%next%>	
}
function window_onunload() {
	
}

function CmdAdd_onclick() {
	window.frm.target="removecanbo";
	window.frm.action="frmdaphannhom.asp?bComm=remove";
	window.frm.submit();

	window.frm.target="addcanbo";
	window.frm.action="frmchuaphannhom.asp";
	window.frm.submit();
	
}

//-->
</SCRIPT>
</head>
<LINK href="../../styles/styles.css" type=text/css rel=STYLESHEET>
<body topmargin="0" leftmargin="0" rightmargin="0" LANGUAGE=javascript onunload="return window_onunload()">
<form method="POST" name=frm>
   <table border="0" width="100%" bgcolor="#bdd5d0" style="border-style: solid">
        <tr>
          <td width="25%"><select size="1" name="ComboValue" style="FONT-FAMILY: Arial; HEIGHT: 23px; POSITION: relative; WIDTH:100%">
			<%if loaitim="" then%>            
				<option selected value="all">
				<option value="ma">Tìm theo mã
				<option value="ten">Tìm theo tên
			 <%end if%>
			 <%if loaitim="ma" then%>            
				<option value="all">
				<option selected value="ma">Tìm theo mã
				<option value="ten">Tìm theo tên 
			<%end if%>
			 <%if loaitim="ten" then%>            
				<option value="all">
				<option value="ma">Tìm theo mã
				<option selected value="ten">Tìm theo tên
			<%end if%>
		</select></td>
        <td width="15%%" align=center>Gi&#225; tr&#7883;</td>
		<td width="45%"><input name="TxtSearch" size="62" style="font-family:Arial; height: 21; width:100%"></td>
        <td width="15%"><input type="button" value="L&#7885;c" name="CmdSearch" style="font-family:Arial; height: 25; position: relative; width:100%" LANGUAGE=javascript onclick="return CmdSearch_onclick()"></td>          
     </tr>
</table>
<!-- Danh sach can bo -->
<table  border="0" width="100%" style="border-style: solid" cellspacing=1 cellpadding=0>
  <tr>
    <td width="100%" colspan="4" bgcolor="#173584" align=center >
	  <input type=button name="CmdAdd" value='Lo&#7841;i c&#225;n b&#7897; kh&#7887;i nh&#243;m' style="font-family:Arial; height: 25; position: relative; width:50%" LANGUAGE=javascript onclick="return CmdAdd_onclick()">
    </td>
 </tr>
 <tr bgcolor="#bdd5d0">
	<td width="5%" align="center">
      <INPUT  name=checkallCB type=checkbox LANGUAGE=javascript onclick="return checkallCB_onclick()" value="ON"></td>
    <td width="15%" align="center">M&#227;</td>
    <td width="60%" align="center">T&#234;n</td>
    <td width="20%" align="center">Ng&#224;y sinh</td>
  </tr>
  <%	
	If Not Rec.EOF Then
		nRecCount = Rec.RecordCount
		Rec.PageSize = 20
		nPageCount = Rec.PageCount
		If nPage < 1 then
			nPage = 1			
		End If
		if nPage > nPageCount Then
			nPage=nPageCount
		end if
		TotalN=rec.recordcount
		%>
		<input type="hidden" name=TotalMax value=<%=TotalN%>>
	<%
		STT=1
		rec.AbsolutePage=nPage
		cnt=1
		do while not Rec.EOF
			if (cnt/2=int(cnt/2)) then
				color="#eeeecc"
			else
				color="#F8F9D9"
			end if
%>
			<tr bgcolor=<%=color%>>
			  <td width="5%" height="1" bgcolor="#bdd5d0" align="center"><INPUT  name=cb<%=STT%> type=checkbox value="ON" ></td>  			         
			  <td width="15%" height="1"><input type="hidden" name=Ma<%=STT%> value=<%=Rec("Macanbo")%>><%=Rec("Macanbo")%></td>
			  <td width="60%" height="1"><%=Rec("hovaten")%></td>
 			  <td width="20%" height="1" align="center"><%=ClsFun.FormatDate(Rec("ngaysinh"))%></td>
			</tr>
<%			STT=STT+1
			Rec.MoveNext
			cnt=cnt+1
		loop
	end if
	rec.Close
	set rec=nothing
%>  			
</table>
</form>
</body>
</html>
<%
	Conn.Close
	Set Conn=nothing
	Set ClsFun=Nothing
%>